<template>
  <div class="index-lists">
    <el-card class="!border-none" shadow="never">
      <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
        <el-form-item label="合同名称" prop="contractName">
          <el-input class="w-[280px]" v-model="queryParams.contractName" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input class="w-[280px]" v-model="queryParams.customerName" />
        </el-form-item>
        <el-form-item label="金额" prop="amount">
          <el-input class="w-[280px]" v-model="queryParams.amount" />
        </el-form-item>
        <el-form-item label="收款金额" prop="gatheringAmount">
          <el-input class="w-[280px]" v-model="queryParams.gatheringAmount" />
        </el-form-item>
        <el-form-item label="合同开始时间" prop="contractStartTime">
          <daterange-picker
              v-model:startTime="queryParams.contractStartTimeStart"
              v-model:endTime="queryParams.contractStartTimeEnd"
          />
        </el-form-item>
        <el-form-item label="合同结束时间" prop="contractEndTime">
          <daterange-picker
              v-model:startTime="queryParams.contractStartTimeStart"
              v-model:endTime="queryParams.contractStartTimeEnd"
          />
        </el-form-item>
        <el-form-item label="合同签约日期" prop="dateContractSigning">
          <el-input class="w-[280px]" v-model="queryParams.dateContractSigning" />
        </el-form-item>
        <!-- 修改查询表单中的是否开卷选项 -->
        <el-form-item label="是否开卷" prop="isUncoil">
          <el-select v-model="queryParams.isUncoil" class="w-[280px]" clearable>
            <el-option label="是" value="1" />
            <el-option label="否" value="0" /> <!-- 将value从2改为0 -->
          </el-select>
        </el-form-item>
        <el-form-item label="对应客户" prop="correspondingCustomer">
          <el-input class="w-[280px]" v-model="queryParams.correspondingCustomer" />
        </el-form-item>
        <el-form-item label="对应商机" prop="correspondingBusiness">
          <el-input class="w-[280px]" v-model="queryParams.correspondingBusiness" />
        </el-form-item>
        <el-form-item label="合同有效时间" prop="contractValidTimeStart">
          <daterange-picker
              v-model:startTime="queryParams.contractValidTimeStart"
              v-model:endTime="queryParams.contractValidTimeStart"
          />
        </el-form-item>
        <el-form-item label="甲方签约人" prop="partySigner">
          <el-input class="w-[280px]" v-model="queryParams.partySigner" />
        </el-form-item>
        <el-form-item label="甲方签约人手机" prop="partyPhone">
          <el-input class="w-[280px]" v-model="queryParams.partyPhone" />
        </el-form-item>
        <el-form-item label="合同类型" prop="contractType">
          <el-select v-model="queryParams.contractType" class="w-[280px]" clearable>
            <el-option label="代理合同" value="1" />
            <el-option label="直销合同" value="2" />
            <el-option label="服务合同" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="乙方签约公司" prop="partybFirm">
          <el-select v-model="queryParams.partybFirm" class="w-[280px]" clearable>
            <el-option label="a" value="1" />
            <el-option label="b" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="乙方签约人" prop="partybSigner">
          <el-input class="w-[280px]" v-model="queryParams.partybSigner" />
        </el-form-item>
        <el-form-item label="乙方签约人手机" prop="partybPhone">
          <el-input class="w-[280px]" v-model="queryParams.partybPhone" />
        </el-form-item>
        <el-form-item label="签约日期" prop="signedDate">
          <daterange-picker
              v-model:startTime="queryParams.signedDateStart"
              v-model:endTime="queryParams.signedDateEnd"
          />
        </el-form-item>
        <el-form-item label="合同领用日期" prop="contractDate">
          <daterange-picker
              v-model:startTime="queryParams.contractDateStart"
              v-model:endTime="queryParams.contractDateEnd"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input class="w-[280px]" v-model="queryParams.remarks" />
        </el-form-item>
        <el-form-item label="合同状态" prop="contractState">
          <el-select v-model="queryParams.contractState" class="w-[280px]" clearable>
            <el-option label="已完成" value="1" />
            <el-option label="未开始" value="2" />
            <el-option label="进行中" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="协作人" prop="collaborator">
          <el-select v-model="queryParams.collaborator" class="w-[280px]" clearable>
            <el-option label="01" value="1" />
            <el-option label="02" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="resetPage">查询</el-button>
          <el-button type="primary" @click="exportContract()">导出相关案</el-button>
          <el-button @click="resetParams">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="!border-none mt-4" shadow="never">
      <div>
        <!-- <el-button v-perms="['basic:add']" type="primary" @click="handleAdd()">
            <template #icon>
                <icon name="el-icon-Plus" />
            </template>
新增
</el-button> -->
      </div>
      <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
        <el-table-column label="ID" prop="id" min-width="50" />
        <el-table-column type="selection" width="55" />
        <el-table-column label="合同编号" prop="contractId" min-width="100" />
        <el-table-column label="合同名称" prop="contractName" min-width="100">
          <template #default="{ row }">
            <router-link
                style="color: #409EFF"
                :to="{
                      path: getRoutePath('basic:addlist'),
                      query: {
                          id: row.id
                          // type: 'addlist'
                      }
                  }"
            >
              {{ row.contractName }}
            </router-link>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" prop="customerName" min-width="100" />
        <el-table-column label="金额" prop="amount" min-width="100" />
        <el-table-column label="创建人" prop="creator" min-width="100" />
        <el-table-column label="当前状态" prop="currentState" min-width="100" />
        <el-table-column label="官费" prop="officialFee" min-width="100" />
        <el-table-column label="代理费" prop="agencyFee" min-width="100" />
        <el-table-column label="收款日期" prop="gatheringDate" min-width="100" />
        <el-table-column label="收款金额" prop="gatheringAmount" min-width="100" />
        <el-table-column label="当前办理人" prop="currentManager" min-width="100" />
        <el-table-column label="最后办理时间" prop="finalProcessingTime" min-width="100" />
        <el-table-column label="合同开始时间" prop="contractStartTime" min-width="100" />
        <el-table-column label="合同结束时间" prop="contractEndTime" min-width="100" />
        <el-table-column label="合同签约日期" prop="dateContractSigning" min-width="100" />
        <!-- 修改表格列中的显示 -->
        <el-table-column label="是否开卷" prop="isUncoil" min-width="100">
          <template #default="{ row }">
            {{ row.isUncoil === '1' ? '是' : '否' }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作" width="120" fixed="right">
            <template #default="{ row }">
                <el-button
                    v-perms="['basic:edit']"
                    type="primary"
                    link
                    @click="handleEdit(row)"
                >
                    编辑
                </el-button>
                <el-button
                    v-perms="['basic:del']"
                    type="danger"
                    link
                    @click="handleDelete(row.id)"
                >
                    删除
                </el-button>
            </template>
        </el-table-column> -->
      </el-table>
      <div class="flex justify-end mt-4">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
     <export-popup
        v-if="showEdit"
        ref="editRef"
        @success="getLists"
        @close="showEdit = false"
    />
  </div>
</template>
<script lang="ts" setup name="basic">
import { basicDelete, basicLists } from '@/api/basic'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import { getRoutePath } from '@/router'
import {getToken} from "@/utils/auth";
import axios from "axios";
import configs from "@/config";
// import EditPopup from "@/views/client/contract/addContract/caseEdit.vue";
import ExportPopup from "@/views/client/contract/addContract/ExportContract.vue";
// import EditPopup from './edit.vue'
// const editRef = shallowRef<InstanceType<typeof EditPopup>>()
// const showEdit = ref(false)
const queryParams = reactive({
  contractName: '',
  customerName: '',
  amount: '',
  gatheringAmount: '',
  contractStartTimeStart: '',
  contractStartTimeEnd: '',
  contractEndTimeStart: '',
  contractEndTimeEnd: '',
  dateContractSigning: '',
  isUncoil: '',
  correspondingCustomer: '',
  correspondingBusiness: '',
  contractValidTimeStart: '',
  contractValidTimeEnd: '',
  partySigner: '',
  partyPhone: '',
  contractType: '',
  partybFirm: '',
  partybSigner: '',
  partybPhone: '',
  signedDateStart: '',
  signedDateEnd: '',
  contractDateStart: '',
  contractDateEnd: '',
  remarks: '',
  contractState: '',
  collaborator: '',
  signedDate: '',
  contractState:''
})
const showEdit = ref(false)
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const { pager, getLists, resetPage, resetParams } = usePaging({
  fetchFun: basicLists,
  params: queryParams
})

const exportContract = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('export')
}

// const handleEdit = async (data: any) => {
//     showEdit.value = true
//     await nextTick()
//     editRef.value?.open('edit')
//     editRef.value?.getDetail(data)
// }

const handleDelete = async (id: number) => {
  await feedback.confirm('确定要删除？')
  await basicDelete({ id })
  feedback.msgSuccess('删除成功')
  getLists()
}

getLists()
</script>
